$(function () {
    //1.变量抽取
    var ts_datagrid = $("#ts_datagrid");
    var ts_dialog = $("#ts_dialog");
    var ts_form = $("#form");

    ts_datagrid.datagrid({
        fit: true,
        url: '/insurance/query.do?state=2',
        columns: [[
            {field: 'id', title: '保单ID', hidden: true},
            {field: 'sn', title: '保单编号', width: 200},
            {
                field: 'customer', title: '投保人', width: 200, formatter: function (value) {
                    return value ? value.name : '';
                }
            },
            {field: 'applicationDate', title: '申请日期', width: 200},
            {field: 'beginDate', title: '核保日期', width: 200, sortable: true},
            {field: 'endDate', title: '保险截止日', width: 200},
            {field: 'burningTime', title: '保险时长(/年)', width: 200},
            {
                field: 'sale', title: '业务员', width: 200, formatter: function (value) {
                    return value ? value.username : '';
                }
            },
            {
                field: 'audit', title: '审核人', width: 200, formatter: function (value) {
                    return value ? value.username : '';
                }
            },
            {field: 'totalAmount', title: '投保总金额', width: 200},
            {
                field: 'state', title: '状态', width: 200, formatter: function (value) {
                    if (value == 1) {
                        return '<p>暂存单</p>';
                    } else if (value == 2) {
                        return '<p>批改单</p>';
                    } else if (value == 3) {
                        return '<p>待审核单</p>';
                    } else if (value == 4) {
                        return '<p>审核单</p>'
                    }
                }
            }
        ]],
        toolbar: '#tb',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        pagePosition: 'bottom'
    })
    ts_dialog.dialog({
        width: 1200,
        height: 600,
        buttons: '#form_btn',
        closed: true,
        onClose: function () {
            ts_form.form('clear');
        }
    })


    //设置选择客户对话枉的样式及按扭
    var choose_customer_dialog = $("#choose_customer_dialog");
    choose_customer_dialog.dialog({
        width: 800,
        height: 350,
        buttons: '#customer_btns2',
        closed: true,
        modal: true
    });

    var customer_datagrid = $("#customer_datagrid");
    //查询所有的客户信息
    customer_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        striped: true,
        url: "/customer/getAll.do",
        pagination: true,
        singleSelect: true,
        rownumbers: true,
        columns: [[
            {field: 'name', title: '客户名称', width: 70},
            {
                field: 'gender', title: '性别', width: 40, formatter: function (value, row, index) {
                    if (value == null) {
                        return '<p>未知</p>';
                    }
                    if (value) {
                        return '<p>男</p>';
                    }
                    if (!value) {
                        return '<p>女</p>';
                    }
                }
            },
            {field: 'tel', title: '电话', width: 100},
            {field: 'address', title: '地址', width: 100},
            {field: 'idNo', title: '身份证', width: 100}
        ]],
        onDblClickRow: function () {
            sure_customer();
        }
    });


    //汽车
    var choose_car_dialog = $("#choose_car_dialog");
    var car_datagrid = $("#car_datagrid");
    choose_car_dialog.dialog({
        width: 800,
        height: 350,
        buttons: '#car_btns2',
        closed: true,
        modal: true
    });
    //汽车分类下拉框
    $("#cartype").combobox({})
    car_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        striped: true,
        url: "/carInformation/getAll.do",
        pagination: true,
        singleSelect: true,
        rownumbers: true,
        columns: [[
            {field: 'brand', title: '品牌', width: 100},
            {field: 'version', title: '型号', width: 100},
            {field: 'gasnumber', title: '排气量', width: 100},
            {field: 'price', title: '估值', width: 100},
            {
                field: 'type', title: '汽车分类', width: 100,
                formatter: function (value) {
                    return value ? "<font color='blue'>载客</font>" : "<font color='red'>载物</font>"
                }
            },
            {
                field: 'size', title: '大小', width: 100,
                formatter: function (value, row, index) {
                    if (value == 0 && value == '') {
                        return "<p>小型</p>";
                    } else if (value == 1) {
                        return "<p>中型</p>";
                    } else if (value == 2) {
                        return "<p>大型</p>";
                    } else {
                        return "<p>超大型</p>";
                    }
                }
            }
        ]],
        onDblClickRow: function () {
            sure_car();
        }
    });

    //机构
    var organization_select = $("#organization_select");
    organization_select.combogrid({
        url: '/organization/getAll.do',
        panelWidth: 450,
        value: '请选择',
        idField: 'name',
        textField: 'name',
        columns: [[
            {field: 'id', title: '机构编号', width: 50},
            {field: 'sn', title: '机构代码', width: 100},
            {field: 'name', title: '机构名称', width: 100},
            {field: 'legalperson', title: '法人代表', width: 100},
            {field: 'identity', title: '法人身份证', width: 100},
            {field: 'tel', title: '', width: 100},
            {field: 'address', title: '联系地址', width: 100},
            {
                field: 'state', title: '合作关系', width: 100,
                formatter: function (value) {
                    return value ? "<p><font color='blue'>是</font></p>" : "<p><font color='red'>否</font></p>"
                }
            }
        ]],
        onChange: function () {
            var hiddens = $(".product-tr");
            $.each(hiddens, function (index, item) {
                if (index != 0) {
                    $(item).remove();
                }
            });
            $("#totalAmount").html(0);
        }
    })

    //选择产品
    var choose_product_dialog = $("#choose_product_dialog");
    var product_datagrid = $("#product_datagrid");
    choose_product_dialog.dialog({
        width: 800,
        height: 350,
        buttons: '#product_btns2',
        closed: true,
        modal: true
    });
    product_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        striped: true,
        toolbar: '#product_toolbar',
        url: "/product/getAll.do",
        pagination: true,
        rownumbers: true,
        ctrlSelect: true,
        singleSelect: true,
        columns: [[
            {field: 'sn', title: '产品编号', width: 100},
            {field: 'name', title: '产品名称', width: 100},
            {field: 'organization', title: '机构名称', width: 100},
            {
                field: 'organization', title: '机构名称', width: 100,
                formatter: function (value) {
                    return value ? value.name : '';
                }
            },
            {field: 'year', title: '保障年限', width: 100},
            {field: 'coverage', title: '保额', width: 100},
            {field: 'cost', title: '基本年费', width: 100},
            {
                field: 'state', title: '销售状态', width: 100,
                formatter: function (value, row, index) {
                    return value ? "<p><font color='blue'>在售</font></p>" : "<p><font color='red'>停售</font></p>"
                }
            },
            {
                field: 'franchies', title: '不计免赔', width: 100,
                formatter: function (value) {
                    return value ? "<font color='blue'>是</font>" : "<font color='red'>否</font>"
                }
            }
        ]]
    });


    //2.把方法统一放到一个对象中管理
    var methodObj = {
        no: function () {
            var row = ts_datagrid.datagrid('getSelected');
            if (!row) {
                $.messager.alert('温馨提示', '亲,请选择内容', 'warning');
                return;
            }
            $.messager.confirm('确认对话框', '您确定想拒绝该保单？', function (r) {
                if (r) {
                    $.post('/insurance/refuse.do', {id: row.id}, function (data) {
                        if (data.success) {
                            $.messager.alert('温馨提示', '操作成功!', 'info', function () {
                                methodObj.cancel();
                                ts_datagrid.datagrid('reload');
                            })
                        } else {
                            $.messager.alert('温馨提示', data.msg, 'warning');
                        }
                    })
                }
            });
        },
        ok: function () {
            var row = ts_datagrid.datagrid('getSelected');
            if (!row) {
                $.messager.alert('温馨提示', '亲,请选择内容', 'warning');
                return;
            }
            $.messager.confirm('确认对话框', '您确定想提交审核保单？', function (r) {
                if (r) {
                    $.post('/insurance/submitAudit.do', {id: row.id}, function (data) {
                        if (data.success) {
                            $.messager.alert('温馨提示', '操作成功!', 'info', function () {
                                methodObj.cancel();
                                ts_datagrid.datagrid('reload');
                            })
                        } else {
                            $.messager.alert('温馨提示', data.msg, 'warning');
                        }
                    })
                }
            });
        },
        edit: function () {
            //设置可修改
            $(".easyui-combobox").combobox('readonly', false);
            $(".easyui-textbox").textbox('readonly', false);
            $(".easyui-").validatebox('readonly', false);
            $(".easyui-validatebox").validatebox('readonly', false);
            $(".easyui-datebox").datebox('readonly', false);
            $("#choose_customer").show();
            $("#select-car").show();
            $("#form_btn").show();
            $("#delet_prodcut").show();
            var row = ts_datagrid.datagrid('getSelected');
            if (!row) {
                $.messager.alert('温馨提示', '亲,请选择内容', 'warning')
                return;
            }
            var state = row.state;
            ts_dialog.dialog('setTitle', '保单编辑');
            ts_dialog.dialog('open')

            $.get("/insurance/getByIdAndState.do", {id: row.id, state: row.state}, function (data) {
                console.log(data);
                if (data.customer) {
                    $("[name=id]").val(row.id);
                    $("[name='customer.id']").val(data.customer.id);
                    $("[name='customer.name']").val(data.customer.name);
                    console.log(data.customer.gender);
                    $("#customer_gender").combobox("setValue", data.customer.gender);
                    $("[name='customer.tel']").val(data.customer.tel);
                    $("[name='customer.idcard']").val(data.customer.idcard);
                    $("#address").textbox("setValue", data.customer.address);
                }
                if (data.car) {
                    $("[name='car.id']").val(data.car.id);
                    $("#carname").textbox("setValue", data.car.name);
                    $("#carbrand").textbox("setValue", data.car.brand);
                    $("#carversion").textbox("setValue", data.car.version);
                    $("#gasnumber").textbox("setValue", data.car.gasnumber);
                    $("#carnumber").textbox("setValue", data.car.carnumber);
                    $("#type").combobox("setValue", data.car.type);
                    $("#price").textbox("setValue", data.car.price);
                    $("#carsize").combobox("setValue", data.car.size);
                    $("#begindate").datebox('setValue', data.car.begindate);
                }
                if (data.organization && data.product) {
                    var organization = "";
                    $("#hidethis").attr("data-oid", data.product.id);
                    $("#hidethis").find("#productName").html(data.product.name);
                    $("#hidethis").find("#productSn").html(data.product.sn);
                    $("#hidethis").find("#cost").html(data.product.cost);

                    $("#organization_select").combogrid("setValue", data.organization.name);
                    $("[name='burningTime']").val(data.burningTime);
                    var totalAmount = 0;
                    $.each($(".cost"), function (index, item) {
                        totalAmount = totalAmount + parseInt(item.innerHTML);
                    })
                    var burningTime = $("[name=burningTime]").val();
                    $("#totalAmount").html(totalAmount * burningTime);
                }
                $("#applicationAdvice").textbox("setValue", data.applicationAdvice);
                $("#remark").textbox("setValue", data.remark);
                /*
                    console.log(row);
                    //回显投保人
                    if (row.dept) {
                        row["dept.id"] = row.dept.id;
                    }

                    //回显车辆信息
                    $.get('/employee/getRoleIdByEmployeeId.do', {employeeId: row.id}, function (data) {
                        $("#role_combobox").combobox('setValues', data);
                    })

                    //回显表单
                    ts_form.form('load', row);*/

            });
        },
        check: function () {
            var row = ts_datagrid.datagrid('getSelected');
            if (!row) {
                $.messager.alert('温馨提示', '亲,请选择内容', 'warning')
                return;
            }
            //设置只读
            $(".easyui-combobox").combobox('readonly', true);
            $(".easyui-textbox").textbox('readonly', true);
            $(".easyui-").validatebox('readonly', true);
            $(".easyui-validatebox").validatebox('readonly', true);
            $(".easyui-datebox").datebox('readonly', true);
            $("#choose_customer").hide();
            $("#select-car").hide();
            $("#form_btn").hide();
            $("#delet_prodcut").hide();
            var state = row.state;
            ts_dialog.dialog('setTitle', '保单编辑');
            ts_dialog.dialog('open')

            $.get("/insurance/getByIdAndState.do", {id: row.id, state: row.state}, function (data) {
                console.log(data);
                $("[name=id]").val(row.id);
                $("[name='customer.id']").val(data.customer.id);
                $("[name='customer.name']").val(data.customer.name);
                $("#customer_gender").combobox("setValue", data.customer.gender);
                $("[name='customer.tel']").val(data.customer.tel);
                $("[name='customer.idcard']").val(data.customer.idcard);
                $("#address").textbox("setValue", data.customer.address);


                $("[name='car.id']").val(data.car.id);
                $("#carname").textbox("setValue", data.car.name);
                $("#carbrand").textbox("setValue", data.car.brand);
                $("#carversion").textbox("setValue", data.car.version);
                $("#gasnumber").textbox("setValue", data.car.gasnumber);
                $("#carnumber").textbox("setValue", data.car.carnumber);
                $("#type").combobox("setValue", data.car.type);
                $("#price").textbox("setValue", data.car.price);
                $("#carsize").combobox("setValue", data.car.size);
                $("#begindate").datebox('setValue', data.car.begindate);

                var organization = "";
                console.log(product.id);
                $("#hidethis").attr("data-oid", data.product.id);
                console.log($("#hidethis").attr("data-oid"));
                $("#hidethis").find("#productName").html(data.product.name);
                $("#hidethis").find("#productSn").html(data.product.sn);
                $("#hidethis").find("#cost").html(data.product.cost);

                $("#organization_select").combogrid("setValue", data.organization.name);
                $("[name='burningTime']").val(data.burningTime);
                var totalAmount = 0;
                $.each($(".cost"), function (index, item) {
                    totalAmount = totalAmount + parseInt(item.innerHTML);
                })
                var burningTime = $("[name=burningTime]").val();
                $("#totalAmount").html(totalAmount * burningTime);
                $("#applicationAdvice").textbox("setValue", data.applicationAdvice);
                $("#remark").textbox("setValue", data.remark);
                /*
                    console.log(row);
                    //回显投保人
                    if (row.dept) {
                        row["dept.id"] = row.dept.id;
                    }

                    //回显车辆信息
                    $.get('/employee/getRoleIdByEmployeeId.do', {employeeId: row.id}, function (data) {
                        $("#role_combobox").combobox('setValues', data);
                    })

                    //回显表单
                    ts_form.form('load', row);*/


            });
        },
        reload: function () {
            ts_datagrid.datagrid('reload');
        },
        save: function () {
            ts_form.form('submit', {
                url: '/insurance/saveOrUpdate.do',
                onSubmit: function (param) {
                    param['product.id'] = $("#hidethis").attr("data-oid");
                    param.state = 1;
                    param.totalAmount = $("#totalAmount").html();
                },
                success: function (data) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert('温馨提示', '保存成功!', 'info', function () {
                            methodObj.cancel();
                            ts_datagrid.datagrid('reload');
                        })
                    } else {
                        $.messager.alert('温馨提示', data.msg, 'warning')
                    }
                }
            });
        },
        cancel: function () {
            ts_dialog.dialog('close')
        },
        query: function () {
            //获取输入框的内容
            var customerNameOrTel = $("[name=customerNameOrTel]").val();
            var querySn = $("[name=querySn]").val();
            ts_datagrid.datagrid('load', {
                customerNameOrTel: customerNameOrTel,
                querySn: querySn
            })
        },
//弹出选择客户窗口
        choose_customer: function () {
            choose_customer_dialog.dialog("setTitle", "请选择客户");
            choose_customer_dialog.dialog("open");
        },

//选择客户
        select_customer: function () {
            sure_customer();
        },

//选择汽车
        choose_car: function () {
            choose_car_dialog.dialog("setTitle", "请选择车型");
            choose_car_dialog.dialog("open")
        },
        select_car: function () {
            sure_car();
        },

//添加产品
        add_product: function () {
            var organizationName = $("#organization_select").combobox("getValue");
            if (organizationName == "请选择" || organizationName == null || organizationName == '') {
                $.messager.alert('温馨提示', ' 请选择承保机构！', "warning");
                return;
            }
            choose_product_dialog.dialog("open");
            choose_product_dialog.dialog("setTitle", "请选择保险产品");
            $.post("/product/listAll.do", {organizationName: organizationName, state: true}, function (data) {
                product_datagrid.datagrid("loadData", data);
            });
        },

//选择产品，计算总金额
        select_product: function () {
            //添加所有选中的产品到列表中
            var product = product_datagrid.datagrid("getSelected");
            /* //获取已有产品的id
             var oids = $.map($(".product-tr"), function (item, index) {
                 return $(item).attr("data-oid");
             });*/
            if (product != null) {
                //插入产品
                $("#hidethis").attr("data-oid", product.id);
                $("#hidethis").find("#productName").html(product.name);
                $("#hidethis").find("#productSn").html(product.sn);
                $("#hidethis").find("#cost").html(product.cost);
                /* $.each(products, function (index, item) {
                     if ($.inArray(item.id + "", oids) == -1) {
                         var clone = $("#hidethis").clone(true);
                         clone.show();
                         clone.
                         attr("data-oid", item.id);
                         clone.find("#productName").html(item.name);
                         clone.find("#productSn").html(item.sn);
                         clone.find("#cost").html(item.cost);
                         clone.insertAfter($("#hidethis"));
                     }
                 });*/
                //计算总金额
                calculate();
            }
            //关闭弹窗
            choose_product_dialog.dialog("close");
        }
    }

    //3.给按钮统一绑定点击事件
    $("a[data-cmd]").click(function () {
        //获取按钮的data-cmd属性值
        var methodName = $(this).data('cmd');
        methodObj[methodName]();
    })
})


//选择客户
function sure_customer() {
    var customer = $("#customer_datagrid").datagrid("getSelected");
    if (customer != null) {
        $("[name='customer.id']").val(customer.id);
        $("[name='customer.idNo']").val(customer.idNo);
        $("[name='customer.tel']").val(customer.tel);
        $("#address").textbox("setValue", customer.address);
        $("[name='customer.name']").val(customer.name);
        $("#customergender").combobox("setValue", customer.gender);
    }
    $("#choose_customer_dialog").dialog("close");
}

//选择汽车
function sure_car() {
    var car = $("#car_datagrid").datagrid("getSelected");
    if (car != null) {
        $("#carbrand").textbox("setValue", car.brand);
        $("#carversion").textbox("setValue", car.version);
        $("#gasnumber").textbox("setValue", car.gasnumber);
        $("#cartype").combobox("setValue", car.type);
        $("#carsize").combobox("setValue", car.size);
        $("#price").textbox("setValue", car.price);
    }
    $("#choose_car_dialog").dialog("close");
}


//计算总金额
function calculate() {
    var totalAmount = 0;
    $.each($(".cost"), function (index, item) {
        if (parseInt(item.innerHTML)) {
            totalAmount = totalAmount + parseInt(item.innerHTML);
        }
    })
    var burningTime = 0
    if ($("[name=burningTime]").val()) {
        burningTime = $("[name=burningTime]").val();
    }
    $("#totalAmount").html(totalAmount * burningTime);

}

//删除产品
function delete_this() {
    $("#hidethis").find("#productName").html("");
    $("#hidethis").find("#productSn").html("");
    $("#hidethis").find("#cost").html("");
    $("#organization_select").combogrid("setValue", "请选择");
    $("[name='burningTime']").val('');
}

/*//暂存
function tempStor_submit() {
    $("#form").form("submit", {
        url: '/insurances/saveOrUpdate.do?state=1',
        onSubmit: function (param) {
              param['product.id']= $("#hidethis").attr("data-oid");
            param.totalAmount = $("#totalAmount").html();
        },
        success: function (data) {
            data = $.parseJSON(data)
            if (!data.success) {
                $.messager.alert("保单暂存失败", data.msg, "error");
            } else {
                $.messager.alert("保单已提审", data.msg, "info", function () {
                    $("#form").form('clear');
                });
            }
        }
    });
}

//提审
function preAudit_submit() {
    $("#form").form("submit", {
        url: '/insurances/saveOrUpdate.do?state=3',
        onSubmit: function (param) {
             param['product.id'] = $("#hidethis").attr("data-oid");
            param.totalAmount = $("#totalAmount").html();
        },
        success: function (data) {
            data = $.parseJSON(data)
            console.log(data);
            if (!data.success) {
                $.messager.alert("保单暂存失败", data.msg, "error");
            } else {
                $.messager.alert("保单已提审", data.msg, "info", function () {
                    $("#form").form('clear');
                    // window.location.href = "/insurance/audit.do";
                });
            }
        }
    });
}*/

//输入验证
$.extend($.fn.validatebox.defaults.rules, {
    idcard: {// 验证身份证
        validator: function (value) {
            return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
        },
        message: '身份证号码格式不正确'
    },
    minLength: {
        validator: function (value, param) {
            return value.length >= param[0];
        },
        message: '请输入至少（2）个字符.'
    },
    length: {
        validator: function (value, param) {
            var len = $.trim(value).length;
            return len >= param[0] && len <= param[1];
        },
        message: "输入内容长度必须介于{0}和{1}之间."
    },
    phone: {// 验证电话号码
        validator: function (value) {
            return /^((\d2,3)|(\d{3}\-))?(0\d2,3|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
        },
        message: '格式不正确,请使用下面格式:020-88888888'
    },
    mobile: {// 验证手机号码
        validator: function (value) {
            return /^(13|15|18)\d{9}$/i.test(value);
        },
        message: '手机号码格式不正确'
    },
    intOrFloat: {// 验证整数或小数
        validator: function (value) {
            return /^\d+(\.\d+)?$/i.test(value);
        },
        message: '请输入数字，并确保格式正确'
    },
    currency: {// 验证货币
        validator: function (value) {
            return /^\d+(\.\d+)?$/i.test(value);
        },
        message: '货币格式不正确'
    },
    qq: {// 验证QQ,从10000开始
        validator: function (value) {
            return /^[1-9]\d{4,9}$/i.test(value);
        },
        message: 'QQ号码格式不正确'
    },
    integer: {// 验证整数 可正负数
        validator: function (value) {
            //return /^[+]?[1-9]+\d*$/i.test(value);

            return /^([+]?[0-9])|([-]?[0-9])+\d*$/i.test(value);
        },
        message: '请输入整数'
    },
    age: {// 验证年龄
        validator: function (value) {
            return /^(?:[1-9][0-9]?|1[01][0-9]|120)$/i.test(value);
        },
        message: '年龄必须是0到120之间的整数'
    },

    chinese: {// 验证中文
        validator: function (value) {
            return /^[\Α-\￥]+$/i.test(value);
        },
        message: '请输入中文'
    },
    english: {// 验证英语
        validator: function (value) {
            return /^[A-Za-z]+$/i.test(value);
        },
        message: '请输入英文'
    },
    unnormal: {// 验证是否包含空格和非法字符
        validator: function (value) {
            return /.+/i.test(value);
        },
        message: '输入值不能为空和包含其他非法字符'
    },
    username: {// 验证用户名
        validator: function (value) {
            return /^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value);
        },
        message: '用户名不合法（字母开头，允许6-16字节，允许字母数字下划线）'
    },
    faxno: {// 验证传真
        validator: function (value) {
            //            return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i.test(value);
            return /^((\d2,3)|(\d{3}\-))?(0\d2,3|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
        },
        message: '传真号码不正确'
    },
    zip: {// 验证邮政编码
        validator: function (value) {
            return /^[1-9]\d{5}$/i.test(value);
        },
        message: '邮政编码格式不正确'
    },
    ip: {// 验证IP地址
        validator: function (value) {
            return /d+.d+.d+.d+/i.test(value);
        },
        message: 'IP地址格式不正确'
    },
    name: {// 验证姓名，可以是中文或英文
        validator: function (value) {
            return /^[\Α-\￥]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value);
        },
        message: '请输入姓名'
    },
    date: {// 验证姓名，可以是中文或英文
        validator: function (value) {
            //格式yyyy-MM-dd或yyyy-M-d
            return /^(?:(?!0000)[0-9]{4}([-]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-]?)0?2\2(?:29))$/i.test(value);
        },
        message: '清输入合适的日期格式'
    },
    msn: {
        validator: function (value) {
            return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value);
        },
        message: '请输入有效的msn账号(例：abc@hotnail(msn/live).com)'
    },
    same: {
        validator: function (value, param) {
            if ($("#" + param[0]).val() != "" && value != "") {
                return $("#" + param[0]).val() == value;
            } else {
                return true;
            }
        },
        message: '两次输入的密码不一致！'
    }
});
